<template>
  <view>
    <view @click="checkPermission">
      <template v-if="url">
        <image :src="url" style="width: 80rpx; height: 80rpx; border-radius: 50%" mode="aspectFill"></image>
      </template>
      <template v-else>
        <image src="https://applet.youtuyiliao.com/profile/upload/xiaochengxu/static/avatar.png"
          style="width: 80rpx; height: 80rpx; border-radius: 50%" mode="aspectFill"></image>
      </template>
    </view>
  </view>
</template>

<script>
import * as permissionCheck from '@/chronicDisease/utils/permissionCheck.js'
export default {
  props: {
    url: {
      type: String,
      default: () => ''
    },
  },
  data() {
    return {
      baseUrl: ''
    }
  },
  created() {
    this.baseUrl = this.$store.state.chronic.baseUrl + '/user/upload/public/uploadImage'
  },
  methods: {

    //添加照片
    addImg() {
      var that = this
      uni.chooseImage({
        count: 1, //默认9
        sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
        sourceType: ['album', "camera"], //从相册,摄像头选择
        success: (res) => {
          console.log(res)
          let that = this
          uni.uploadFile({
            url: that.baseUrl,
            filePath: res.tempFilePaths[0],
            name: 'file',
            success: (res) => {
              console.log("维吾尔", res)
              let img = JSON.parse(res.data)
              console.log("维吾尔", img)
              // that.pic_arr.push(img.data)
              console.log("维吾尔3", img.data.uploadUrl)
              let uploadimg = img.data.uploadUrl
              this.$emit('upload', uploadimg)
            }
          });
        }
      })
    },
    checkPermission() {
      permissionCheck.premissionCheckWrap('CAMERA_EXTERNAL_STORAGE').then(() => {
        this.addImg()
      })
    }
  }
}
</script>

<style></style>